﻿using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Model;
using Model.Model;
using Model.View;

namespace Utils.UserHelper;

public static class UserMemory
{
    public static async Task MemoryUser(ViewUser user)
    {
        await using var db = new DataDbContent();
        var having = await db.LoginMemory!
            .FirstOrDefaultAsync(e => e.IsUsing == "use");
        if (having is null)
        {
            await db.LoginMemory!.AddAsync(new LoginMemoryModel
            {
                IsMemory = user.Memory,
                Account = user.Account,
                Password = user.Password,
                IsUsing = "use"
            });
            await db.SaveChangesAsync();
        }
    }
}